//
//  FANMainTabController.swift
//  Weibo - Swift
//
//  Created by user on 16/4/16.
//  Copyright © 2016年 user. All rights reserved.
//

import UIKit

class FANMainTabController: UITabBarController {

    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        let callAddButton:(()->())? = {
            
//            print("点了Button")
            let composeView = FANComposeView()
            
//            self.view.addSubview(composeView)
            composeView.show(self)
         
        }
        
        let tabBar = FANTabBar()
        
        tabBar.callAddButton = callAddButton
        
        self.setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(FANHomeTableViewController(), title: "首页", imageName:"tabbar_home")
        
        addChildViewController(FANMessageTableViewController(), title: "消息",imageName:"tabbar_message_center")

        addChildViewController(FANDiscoverTableViewController(), title: "发现",imageName:"tabbar_discover")

        addChildViewController(FANProfileTableViewController(), title: "我",imageName: "tabbar_profile")
        
    }
    
    func addChildViewController(Vc: UIViewController, title:String ,imageName:String) {
        
        Vc.title = title
        
        Vc.tabBarItem.image = UIImage(named: imageName)
        
        Vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        Vc.tabBarItem .setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(UINavigationController(rootViewController: Vc))
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
